package com.krtech.wecard.module.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.krtech.wecard.framework.model.PageResponse;
import com.krtech.wecard.module.sys.entity.SysUser;
import com.krtech.wecard.module.sys.entity.SysUserOperateLog;
import com.krtech.wecard.module.sys.service.SysUserOperateLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "用户变更记录")
@RestController
@RequestMapping("/sys/userOperate")
@Slf4j
public class SysUserOperateLogController {

    @Autowired
    private SysUserOperateLogService userOperateLogService;



    /**
     * 分页查询,根据用户
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询,根据用户")
    public Page<SysUserOperateLog> page(Page<SysUserOperateLog> page, SysUser sysUser) {
        QueryWrapper<SysUserOperateLog> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc(SysUserOperateLog.COL_ID);

        if (sysUser != null && sysUser.getUserId() != null){
            wrapper.eq(SysUserOperateLog.COL_USER_ID,sysUser.getUserId());
        }else  if (sysUser != null && sysUser.getUserCode() != null){
            wrapper.eq(SysUserOperateLog.COL_USER_CODE,sysUser.getUserCode());
        }

        Page<SysUserOperateLog> logPage = userOperateLogService.page(page, wrapper);
        return logPage;
    }

    /**
     * 列表查询,根据用户
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表查询,根据用户")
    public List<SysUserOperateLog> list( SysUser sysUser) {
        QueryWrapper<SysUserOperateLog> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc(SysUserOperateLog.COL_ID);

        if (sysUser != null && sysUser.getUserId() != null){
            wrapper.eq(SysUserOperateLog.COL_USER_ID,sysUser.getUserId());
        }else  if (sysUser != null && sysUser.getUserCode() != null){
            wrapper.eq(SysUserOperateLog.COL_USER_CODE,sysUser.getUserCode());
        }

        List<SysUserOperateLog> logList = userOperateLogService.list(wrapper);
        return logList;
    }
}
